package org.nicholasjones.radiocontroller.comms;

import static java.lang.String.format;

/**
 * <code>CommsException</code> signals that an error occurred whilst performing communications request.
 * @author Nicholas Jones
 * Date: 6/4/13
 * Time: 9:01 PM
 * @see Exception
 */
public class CommsException extends Exception {

    private static final long serialVersionUID = 5135645415846677164L;

    private String statusCode;

    /**
     * Constructs a <code>ServiceException</code> with a status code and detailed message.
     *
     * @param statusCode - the status code to set.
     * @param message - the message to set.
     */
    public CommsException(final String statusCode, final String message) {
        super(message);
        setStatusCode(statusCode);
    }

    /**
     * Returns the status code for this throwable.
     * @return the status code for this throwable or null if it is not set
     */
    public String getStatusCode() {
        return statusCode;
    }

    /**
     * Sets the status code for this throwable.
     *
     * @param statusCode the error code to set
     */
    public void setStatusCode(final String statusCode) {
        this.statusCode = statusCode;
    }

    /**
     * Returns the string representation of the exception.
     * @return the message in a readable format.
     */
    @Override
    public String toString() {
        return format("[%s][statusCode=%s][message=%s]", this.getClass().getSimpleName(), statusCode, getMessage());
    }

}